package ace.module.stock.sdk.core.feign.impl;

import ace.cmp.core.model.R;
import ace.cmp.openfeign.security.oauth2.core.config.FeignInternalServerOauth2SecurityConfig;
import ace.module.common.api.annotation.ApiRemoteProxyPriority;
import ace.module.common.api.model.input.TenantAndAppTypeInput;
import ace.module.stock.api.model.dto.WmsStockDto;
import ace.module.stock.api.model.dto.ext.WmsStockDetailDto;
import ace.module.stock.api.model.input.WmsBizInitInput;
import ace.module.stock.api.model.input.WmsStockActionRecordWithBatchSnInput;
import ace.module.stock.api.model.input.WmsStockActionTypeRecordWithBatchSnInput;
import ace.module.stock.api.model.input.WmsStockReverseBatchSnInput;
import ace.module.stock.sdk.core.constant.SdkConstant;
import ace.module.stock.sdk.core.feign.WmsStockFeignApi;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 库存 rpc feign.
 *
 * @author Caspar
 */
@FeignClient(
    name = "${spring.cloud.openfeign.client.config.wmsStockFeign.name:" + SdkConstant.FEIGN_SERVICE_NAME + "}",
    contextId = "wmsStockFeign",
    path = WmsStockFeign.PATH,
    configuration = FeignInternalServerOauth2SecurityConfig.class,
    primary = false
)
@ApiRemoteProxyPriority
public interface WmsStockFeign extends WmsStockFeignApi {

  String PATH = "${spring.cloud.openfeign.client.config.wmsStockFeign.path:/stock/wms-stock/rpc}";

  @Operation(summary = "库存初始化或设置", description = "库存不存在,则初始化库存;存在,则设置库存.并且自动计算总库存")
  @PostMapping("/initOrSet")
  R<WmsStockDetailDto> initOrSet(@Valid @NotNull @RequestBody TenantAndAppTypeInput<WmsBizInitInput> input);

  @Operation(summary = "库存修改", description = "库存增加、扣减或设置.自动计算总库存")
  @PostMapping("/modify/v2")
  R<String> modify(TenantAndAppTypeInput<WmsStockActionTypeRecordWithBatchSnInput> input);

  @Operation(summary = "增加库存", description = "code 0=成功   data=增加操作记录操作批次流水号")
  @PostMapping("/add/v2")
  R<String> add(@Valid @NotNull @RequestBody TenantAndAppTypeInput<WmsStockActionRecordWithBatchSnInput> input);

  @Operation(summary = "扣减库存", description = "code 0=成功   data=扣减操作记录操作批次流水号")
  @PostMapping("/subtract")
  R<String> subtract(@Valid @NotNull @RequestBody TenantAndAppTypeInput<WmsStockActionRecordWithBatchSnInput> input);

  @Operation(summary = "回退增加或扣减库存操作", description = "code 0=成功   data=回退操作记录操作批次流水号")
  @PostMapping("/reverseByUserSn")
  R<String> reverse(@Valid @NotNull @RequestBody TenantAndAppTypeInput<WmsStockReverseBatchSnInput> input);

  @Operation(summary = "获取sku库存,根据业务id.")
  @PostMapping("/getSkuByObjectIdIn")
  R<List<WmsStockDto>> getSkuByObjectIdIn(@Valid @NotNull @RequestBody TenantAndAppTypeInput<List<Long>> skuIdInput);

  @Operation(summary = "获取商品总库存,根据业务id.")
  @PostMapping("/getProductByObjectIdIn")
  R<List<WmsStockDto>> getProductByObjectIdIn(@Valid @NotNull @RequestBody TenantAndAppTypeInput<List<Long>> productIdInput);

}